package com.westos.todo.entity;

import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.FactoryBean;

public class MybatisFactoryBean<T> implements FactoryBean<T>{
	
	private SqlSessionFactory sqlSessionFactory;
	private Class<T> targetClass;

	@Override
	public T getObject() throws Exception {
		
		return sqlSessionFactory.openSession().getMapper(targetClass);
	}

	@Override
	public Class<T> getObjectType() {
		
		return targetClass;
	}

	@Override
	public boolean isSingleton() {
		
		return true;
	}

	public SqlSessionFactory getSqlSessionFactory() {
		return sqlSessionFactory;
	}

	public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
		this.sqlSessionFactory = sqlSessionFactory;
	}

	public Class<T> getTargetClass() {
		return targetClass;
	}

	public void setTargetClass(Class<T> targetClass) {
		this.targetClass = targetClass;
	}
	

}
